<template>
  <div style="width:60%">
    <a-form-model :label-col="{ span: 3 }" :wrapperCol="{ span: 14 }">
      <a-form-model-item label="节点ID">
        <span>{{ID}}</span>
      </a-form-model-item>
       <a-form-model-item label="节点名称">
        <a-input v-model="name"></a-input>
      </a-form-model-item>
      <a-form-model-item label="数据库密码">
        <a-input-password placeholder="input password" v-model="dbPassword" />
      </a-form-model-item>
      <a-form-model-item label="MQTT消息队列">
        <a-input v-model="mqttAddr"></a-input>
        <a-input v-model="mqttUser"></a-input>
        <a-input-password v-model="mqttPassword" placeholder="input password" />
      </a-form-model-item>
      <a-form-model-item label="Redis地址">
        <a-input v-model="redisAddr"></a-input>
      </a-form-model-item>
      <a-form-model-item label="Redis用户名">
        <a-input v-model="redisUser"></a-input>
      </a-form-model-item>
      <a-form-model-item label="Redis密码">
        <a-input-password
          v-model="redisPassword"
          placeholder="input password"
        />
      </a-form-model-item>
      <!--<a-form-model-item label="运维服务器">
        <a-input v-model="remoteAddr"></a-input>
      </a-form-model-item>-->

      <a-form-model-item :wrapper-col="{ span: 14, offset: 2 }">
        <a-space>
          <a-button type="primary" @click="refresh"> 刷新 </a-button>
          <a-button type="primary" @click="setCfg"> 下发 </a-button>
          <a-button type="primary" @click="rebootSoft"> 软复位 </a-button>
        </a-space>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>
<script>
import { getCfg, setCfg,rebootSoft } from "@/services/systemcfg";

export default {
  data() {
    return {
      mqttPassword: "",
      mqttUser: "",
      mqttAddr: "",
      redisPassword: "",
      redisAddr: "",
      redisUser: "",
      remoteAddr: "",
      dbPassword: "",
      ID:'',
      name:'',
    };
  },
  created() {
    this.refresh();
  },

  methods: {
    onSubmitIPAddr() {},
    refresh() {
      getCfg().then((data) => {
        this.mqttPassword = data?.mqttPassword;
        this.mqttUser = data?.mqttUser;
        this.mqttAddr = data?.mqttAddr;
        this.redisPassword = data?.redisPassword;
        this.redisUser = data?.redisUser;
        this.dbPassword = data?.dbPassword;
        this.ID = data?.ID
        this.name = data?.name
      });
    },
    setCfg() {
      setCfg(
        this.mqttAddr,
        this.mqttUser,
        this.mqttPassword,
        this.redisUser,
        this.redisPassword,
        this.dbPassword,
        this.name
      );
    },
    rebootSoft(){
      rebootSoft()
    }
  },
};
</script>